package zeroj.web.context;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import zeroj.resource.ResourceInjector;

/**
 * 
 * @author LYL(lylsir at gmail dot com)
 * 
 */
public class ContextLoadListener implements ServletContextListener {

	private static final Log log = LogFactory.getLog(ContextLoadListener.class);
	static final String ResourcePackageName = "resource-packages";
	
	public void contextDestroyed(ServletContextEvent event) {

		log.debug("destroying ...");
		ResourceInjector.destroy();
	}

	public void contextInitialized(ServletContextEvent event) {

		log.debug("initing ...");
		String packageNames = event.getServletContext().getInitParameter(ResourcePackageName);
		ResourceInjector.initResources(packageNames);
	}

}
